<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateHelpAnswersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('help_answers', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('help_request_id');
            $table->unsignedBigInteger('user_id');
            $table->text('answer_content');
            $table->boolean('is_ai_generated')->default(false);
            $table->unsignedInteger('upvotes_count')->default(0);
            $table->boolean('is_best_answer')->default(false);
            $table->boolean('is_hidden')->default(false)->comment('是否被隐藏');
            $table->timestamp('created_at')->useCurrent();
            
            // 外键约束
            $table->foreign('help_request_id')->references('id')->on('help_requests')->onDelete('cascade');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            
            // 索引
            $table->index(['help_request_id']);
            $table->index(['user_id']);
            $table->index(['is_best_answer']);
            $table->index(['is_hidden']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('help_answers');
    }
}